import yaml
import os


# 读取yaml文件，以字典类型存储
def load_yaml(filename):
    try:
        with open(filename, 'r', encoding='utf-8') as stream:
            docs = yaml.load_all(stream, Loader=yaml.FullLoader)
            param_dict = dict()
            for doc in docs:
                for k, v in doc.items():
                    param_dict[k] = v
            return param_dict
    except Exception as e:
        print(f"读取配置文件失败\n{e}")


if __name__ == '__main__':
    par_dir_path = os.path.abspath(os.path.join(os.getcwd(), '..'))
    yaml_config_path = os.path.join(par_dir_path, 'config_info.yaml')
    # params = GetParamsFromYaml(os.path.join(os.path.pardir(),'config_info.yaml'))
    params = load_yaml(yaml_config_path)
    print(params)
    print(type(params))
